package com.oa.android.server;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.oa.android.MainActivity;
import com.oa.android.activity.OnePiexlActivity;
import com.oa.android.activity.WelcomeActivity;

/**
 * Created by zouqh on 2018/4/21.
 */

public class OnePixelReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) {    //屏幕关闭启动1像素Activity
            Log.i("屏幕关闭", "启动一像素");
            if (null == MainActivity.mainActivity) {
                Intent it = new Intent(context, OnePiexlActivity.class);
                it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(it);
            }

//            if (null == MainActivity.mainActivity) {
//                Intent it = new Intent(context, WelcomeActivity.class);
//                it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                context.startActivity(it);
//            }
        } else if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) {   //屏幕打开 结束1像素
            Log.i("屏幕开启", "关闭一像素");
            context.sendBroadcast(new Intent("finish"));
            Intent main = new Intent(Intent.ACTION_MAIN);
            main.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            main.addCategory(Intent.CATEGORY_HOME);
            context.startActivity(main);
//            Intent intent1 = new Intent();
//// 为Intent设置Action、Category属性
//            intent.setAction(Intent.ACTION_MAIN);// "android.intent.action.MAIN"
//            intent.addCategory(Intent.CATEGORY_HOME); //"android.intent.category.HOME"
//            context.startActivity(intent1);
        }
    }
}